﻿// =====================================================================
//
//  This file is part of the Microsoft Dynamics CRM SDK code samples.
//
//  Copyright (C) Microsoft Corporation.  All rights reserved.
//
//  This source code is intended only as a supplement to Microsoft
//  Development Tools and/or on-line documentation.  See these other
//  materials for detailed information regarding Microsoft code samples.
//
//  THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//
// =====================================================================
using System;
using System.Runtime.Serialization;

namespace Microsoft.Xrm.Sdk.Metadata
{
	[DataContract(Name = "AttributeMetadata", Namespace = XmlNamespaces.V5.Metadata)]
	[KnownType(typeof(BooleanAttributeMetadata))]
	[KnownType(typeof(DateTimeAttributeMetadata))]
	[KnownType(typeof(DecimalAttributeMetadata))]
	[KnownType(typeof(DoubleAttributeMetadata))]
	[KnownType(typeof(EntityNameAttributeMetadata))]
	[KnownType(typeof(IntegerAttributeMetadata))]
	[KnownType(typeof(BigIntAttributeMetadata))]
	[KnownType(typeof(LookupAttributeMetadata))]
	[KnownType(typeof(MemoAttributeMetadata))]
	[KnownType(typeof(MoneyAttributeMetadata))]
	[KnownType(typeof(PicklistAttributeMetadata))]
	[KnownType(typeof(StateAttributeMetadata))]
	[KnownType(typeof(StatusAttributeMetadata))]
	[KnownType(typeof(StringAttributeMetadata))]
	[KnownType(typeof(ManagedPropertyAttributeMetadata))]
	public class AttributeMetadata : MetadataBase
	{
		#region Fields
		private string _attributeOf;
		private AttributeTypeCode? _attributeType;
		private int? _columnNumber;
		private Label _description;
		private Label _displayName;
		private string _entityLogicalName;
		private BooleanManagedProperty _isAuditEnabled;
		private bool? _isCustomAttribute;
		private bool? _isPrimaryId;
		private bool? _isPrimaryAttribute;
		private Guid? _linkedAttributeId;
		private string _logicalName;
		private string _schemaName;
		private bool? _validForCreate;
		private bool? _validForRead;
		private bool? _validForUpdate;
		private bool? _isSecured;
		private bool? _canBeSecuredForRead;
		private bool? _canBeSecuredForCreate;
		private bool? _canBeSecuredForUpdate;
		private bool? _isManaged;
		private string _deprecatedVersion;

		private BooleanManagedProperty _isCustomizable;
		private BooleanManagedProperty _isRenameable;
		private BooleanManagedProperty _isValidForAdvancedFind;
		private AttributeRequiredLevelManagedProperty _requiredLevel;
		private BooleanManagedProperty _canModifyAdditionalSettings;

		private string _aggregateOf;
		private bool? _isLogical;
		private int _displayMask;
		#endregion

		#region Constructors
		public AttributeMetadata()
		{
		}

		protected AttributeMetadata(AttributeTypeCode attributeType)
			: this()
		{
			this.AttributeType = attributeType;
		}

		protected AttributeMetadata(AttributeTypeCode attributeType, string schemaName)
			: this(attributeType)
		{
			this.SchemaName = schemaName;
		}
		#endregion

		#region Properties
		[DataMember]
		public string AttributeOf
		{
			get { return this._attributeOf; }
			internal set { this._attributeOf = value; }
		}

		[DataMember]
		public AttributeTypeCode? AttributeType
		{
			get { return this._attributeType; }
			internal set { this._attributeType = value; }
		}

		[DataMember]
		public int? ColumnNumber
		{
			get { return this._columnNumber; }
			internal set { this._columnNumber = value; }
		}

		/// <summary>
		/// Gets or sets the description for the attribute.  This is valid for both the Create and Update of an attribute.
		/// </summary>
		[DataMember]
		public Label Description
		{
			get { return this._description; }
			set { this._description = value; }
		}

		[DataMember]
		public Label DisplayName
		{
			get { return this._displayName; }
			set { this._displayName = value; }
		}

		/// <summary>
		/// Gets the version an attribute was deprecated in.
		/// This is the assembly version of the product's release
		/// </summary>
		[DataMember]
		public string DeprecatedVersion
		{
			get { return this._deprecatedVersion; }
			internal set { this._deprecatedVersion = value; }
		}

		[DataMember]
		public string EntityLogicalName
		{
			get { return this._entityLogicalName; }
			internal set { this._entityLogicalName = value; }
		}

		[DataMember]
		public BooleanManagedProperty IsAuditEnabled
		{
			get { return this._isAuditEnabled; }
			set { this._isAuditEnabled = value; }
		}

		[DataMember]
		public bool? IsCustomAttribute
		{
			get { return this._isCustomAttribute; }
			internal set { this._isCustomAttribute = value; }
		}

		[DataMember]
		public bool? IsPrimaryId
		{
			get { return this._isPrimaryId; }
			internal set { this._isPrimaryId = value; }
		}

		[DataMember]
		public bool? IsPrimaryName
		{
			get { return this._isPrimaryAttribute; }
			internal set { this._isPrimaryAttribute = value; }
		}

		[DataMember]
		public bool? IsValidForCreate
		{
			get { return this._validForCreate; }
			internal set { this._validForCreate = value; }
		}

		[DataMember]
		public bool? IsValidForRead
		{
			get { return this._validForRead; }
			internal set { this._validForRead = value; }
		}

		[DataMember]
		public bool? IsValidForUpdate
		{
			get { return this._validForUpdate; }
			internal set { this._validForUpdate = value; }
		}

		[DataMember]
		public bool? CanBeSecuredForRead
		{
			get { return this._canBeSecuredForRead; }
			internal set { this._canBeSecuredForRead = value; }
		}

		[DataMember]
		public bool? CanBeSecuredForCreate
		{
			get { return this._canBeSecuredForCreate; }
			internal set { this._canBeSecuredForCreate = value; }
		}

		[DataMember]
		public bool? CanBeSecuredForUpdate
		{
			get { return this._canBeSecuredForUpdate; }
			internal set { this._canBeSecuredForUpdate = value; }
		}

		[DataMember]
		public bool? IsSecured
		{
			get { return this._isSecured; }
			set { this._isSecured = value; }
		}

		[DataMember]
		public bool? IsManaged
		{
			get { return this._isManaged; }
			internal set { this._isManaged = value; }
		}

		[DataMember]
		public Guid? LinkedAttributeId
		{
			get { return _linkedAttributeId; }
			set { _linkedAttributeId = value; }
		}

		[DataMember]
		public string LogicalName
		{
			get { return this._logicalName; }
			set { this._logicalName = value; }
		}

		[DataMember]
		public BooleanManagedProperty IsCustomizable
		{
			get { return _isCustomizable; }
			set { _isCustomizable = value; }
		}

		[DataMember]
		public BooleanManagedProperty IsRenameable
		{
			get { return _isRenameable; }
			set { _isRenameable = value; }
		}

		[DataMember]
		public BooleanManagedProperty IsValidForAdvancedFind
		{
			get { return this._isValidForAdvancedFind; }
			set { this._isValidForAdvancedFind = value; }
		}

		[DataMember]
		public AttributeRequiredLevelManagedProperty RequiredLevel
		{
			get { return this._requiredLevel; }
			set { this._requiredLevel = value; }
		}

		[DataMember]
		public BooleanManagedProperty CanModifyAdditionalSettings
		{
			get { return _canModifyAdditionalSettings; }
			set { _canModifyAdditionalSettings = value; }
		}

		[DataMember]
		public string SchemaName
		{
			get { return this._schemaName; }
			set { this._schemaName = value; }
		}

		internal int DisplayMask
		{
			get { return _displayMask; }
			set { _displayMask = value; }
		}

		internal string AggregateOf
		{
			get { return _aggregateOf; }
			set { _aggregateOf = value; }
		}


		internal bool? IsLogical
		{
			get { return this._isLogical; }
			set { this._isLogical = value; }
		}
		#endregion
	}
}
